﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MyOA.BLL;
using MyOA.DAL;
using MyOA.Model;

namespace MyOA.UI.ManualSign
{
    public partial class ManualSign : System.Web.UI.Page
    {

        ManualSignManager msm = new ManualSignManager();
        UserInfoService userInfoService = new UserInfoService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["loginId"] == null)
            {
                Response.Redirect("~/Login.aspx");
                return;
            }
            show();
            if (!IsPostBack)
            {
                this.divGo.Visible = false;
                this.divOut.Visible = false;
                btnOut.Enabled = false;
            }
        }
        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAriver_Click(object sender, EventArgs e)
        {
            btnOut.Enabled = true;
            this.divGo.Visible = true;
            string loginId = (string)Session["loginId"];//获得用户名

            MyOA.Model.ManualSign ms = msm.GetManualSignInOf(loginId);

            this.txtName.Text = loginId;
            this.txtNameOff.Text = ms.User.UserName;//获得姓名
            this.txtBuMen.Text = ms.User.Depart.DepartName;//获得部门
            this.txtJiGou.Text = ms.User.Depart.Branch.BranchName;//获得机构
            this.txtSTime.Text = DateTime.Now.ToString();//获得当前时间
            this.txtRemark.Text = this.txtmark.Text;
            this.txtmark.Text = "";//清空备注信息

            //添加员工打卡信息
            MyOA.Model.ManualSign manualSign = new MyOA.Model.ManualSign();
            manualSign.SignTime = DateTime.Now;//获得当前时间
            manualSign.SignTag = 1;//1表示上班，0表示下班
            manualSign.SignDesc = this.txtRemark.Text;//获得备注信息
            manualSign.User = userInfoService.GetUserInfoByLoginId(loginId);
            manualSign.AccessorySize = 1024;//默认员工号
            int result = msm.AddManualSign(manualSign);//把员工信息添加到表中
            if (result > 1)
            {
                Console.WriteLine("添加成功!");
            }
            this.btnAriver.Enabled = false;//隐藏签到按钮

        }

        /// <summary>
        /// 签退
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOut_Click(object sender, EventArgs e)
        {

            this.btnAriver.Enabled = false;
            this.btnOut.Enabled = false;
            this.divGo.Visible = false;
            this.divOut.Visible = true;


            string loginId = (string)Session["loginId"];//获得用户名

            MyOA.Model.ManualSign ms = msm.GetManualSignInOf(loginId);
            this.txtUserName1.Text = loginId;
            UserInfo user = ms.User;
            this.txtName1.Text = ms.User.UserName;//获得姓名
            this.txtBuMen1.Text = ms.User.Depart.DepartName;//获得部门
            this.txtDept.Text = ms.User.Depart.Branch.BranchName;//获得机构
            this.txtDaKaTime.Text = DateTime.Now.ToString();//获得当前时间
            this.txtRemark2.Text = this.txtmark.Text;
            this.txtmark.Text = "";//清空备注信息


            MyOA.Model.ManualSign manualSign = new MyOA.Model.ManualSign();
            manualSign.SignTime = DateTime.Now;
            manualSign.SignTag = 0;
            manualSign.SignDesc = this.txtRemark2.Text;
            manualSign.User = userInfoService.GetUserInfoByLoginId(loginId);
            manualSign.AccessorySize = 1024;
            int result = msm.AddManualSign(manualSign);
            if (result > 1)
            {
                Console.WriteLine("添加成功!");
            }
        }

        public void show()
        {
            this.txtTime.Text = DateTime.Now.ToString("dd/MM/yyyy"); //获得当前时间
        }
    }
}
